/*
 * $Id$
 */
package py.windmill.action;

/**
 *
 * @author myang
 */
public class MimeType {

    public final static MimeType PLAIN = new MimeType("text/plain");
    public final static MimeType HTML = new MimeType("text/html");
    public final static MimeType JSON = new MimeType("application/json");
    public final static MimeType ALL = new MimeType("*/*");

    private String _type;
    private String _attrName;
    private String _attrValue;

    public MimeType(final String type) {
        _type = type;
    }

    public MimeType attr(final String name, final String value) {
        final MimeType t = new MimeType(_type);
        t._attrName = name;
        t._attrValue = value;
        return t;
    }

    public String type() {
        return _type;
    }

    public String toString() {
        final StringBuilder sb = new StringBuilder(_type);
        if (_attrValue != null && _attrValue != null) {
            sb.append(";").append(_attrName).append("=").append(_attrValue);
        }
        return sb.toString();
    }
}
